<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>

<body>
    <script>
        // 1，反转字符串
        /*    var str = "abcdefg";

          // 要求结果
          // gfedcba
          var a = str.split("");
          a.reverse();
          console.log(a); */

        // 2， aabccd统计每个字符出现的次数，去掉重复的字符，使结果显示 abcd
        /* var str = " aabccd";
          var obj = {};
          for (var i = 0; i < str.length; i++) {
              var a = str.charAt(i);
              if (obj[a] == undefined) {
                  obj[a] = 1;
              } else {
                  obj[a]++;
              }
          }
          console.log(obj);
          var str1 = "";
          for (var i in obj) {
              str1 += i;
          }
          console.log(str1); */

        // 3, 编写函数， 判断一个字符串是否是“ 可回文字符串”
        var str = "aabbccdd";
        var obj = {};
        for (var i = 0; i < str.length; i++) {
            if (obj[str[i]]) {
                obj[str[i]]++;
            } else {
                obj[str[i]] = 1;
            }
        }
        console.log(obj);
        var newStr = "";
        for (var key in obj) {
            newStr += key;
        }
        console.log(newStr);
    </script>
</body>

</html>